{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<style>
    .label-default{background-color:#d1dade;color:#5e5e5e;}
    .input-group-addon .radio-inline, .input-group-addon .checkbox-inline{padding-top:0; line-height:0.95;}
    .dropdown-menu{ min-width:145px; }
    .multi-img-details .multi-item{height:auto;}
    #member.multi-img-details .multi-item{text-align:center; max-width:100px;}
    #member.multi-img-details .multi-item img{ max-width:90px; max-height:90px;}
    #member.multi-img-details .multi-item .title{ overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
    #myTab2.nav-tabs{border-color: #1ab394;}
    #myTab2.nav-tabs>li>a{border-radius:0!important;padding: 7px 15px;}
    #myTab2.nav-tabs>li>a:hover{ color:#333}
    #myTab2.nav-tabs>li.active>a, #myTab2.nav-tabs>li.active>a:hover, #myTab2.nav-tabs>li.active>a:focus{color: #FFF;border-radius:0;background-color: #1ab394;border-color: #1ab394;}
    #options.markethide .optmarket, .markethide.market{display:none}
</style>
<link href="{$_W['siteroot']}web/resource/components/select2/select2.min.css" rel="stylesheet">
{if $op == 'post'}
<ol class="breadcrumb we7-breadcrumb" style="display:none">
    <a href="./index.php?c=site&amp;a=article&amp;"><i class="wi wi-back-circle"></i> </a>
    <li><a href="./index.php?c=site&amp;a=article&amp;">照片管理</a></li>
    <li><a href="./index.php?c=site&amp;a=article&amp;do=post&amp;">照片编辑</a></li>
</ol>
<ul class="nav nav-tabs" id="myTab">
    <li class="active"><a href="#tab_basic">照片编辑</a></li>
</ul>

<div class="main">
    <form action="" method="post" onsubmit="return check(this)" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="photoid" value="{$photoid}"/>
        <div class="tab-content" style="height: 500px">
            <div class="tab-pane in active" id="tab_basic">
                <div class="panel panel-default">
                    <div class="panel-heading">基本设置</div>
                    <div class="panel-body">
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">绑定图片后台活动</label>
                            <div class="col-md-6">
                                <select class="form-control" name="photo[raceid]">
                                    {loop $activity $v}
                                    <option value="{$v['raceid']}" {if $photo['raceid']==$v['raceid']}selected="selected"{/if}>{$v['name']}</option>
                                    {/loop}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">背景图片</label>
                            <div class="col-sm-9 col-xs-12">
                                <input type="hidden" name="thumb_old" value="{$photo['bgimg']}">
                                {php echo tpl_form_field_image('photo[bgimg]', $photo['bgimg']);}
                                <span class="help-block">图片建议大小：640×380像素</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">轮播图</label>
                            <div class="col-sm-9">
                                {php echo tpl_form_field_multi_image('img',unserialize($photo['atlas']));}
                                <span class="help-block">图片建议大小：640×380像素</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">轮播图连接</label>
                            <div class="col-sm-9 col-xs-12">
                                <select name="photo[link]" class="form-control">
                                    {loop $temp $value}
                                    <option value="{$value['link']}" {if $photo['link'] == $value['link']}selected{/if}>{$value['title']}</option>
                                    {/loop}
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">分享标题</label>
                            <div class="col-sm-9 col-xs-12">
                                <textarea class="form-control" name="photo[share_title]" rows="3" placeholder="微信分享标题">{$photo['share_title']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">分享描述</label>
                            <div class="col-sm-9 col-xs-12">
                                <textarea class="form-control" name="photo[share_desc]" rows="3" placeholder="微信分享描述">{$photo['share_desc']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">分享链接</label>
                            <div class="col-sm-9 col-xs-12">
                                <textarea class="form-control" name="photo[share_link]" rows="3" placeholder="微信分享链接">{$photo['share_link']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12 col-sm-3 col-md-2 control-label">缩略图片</label>
                            <div class="col-sm-9 col-xs-12">
                                <input type="hidden" name="thumb_old" value="{$photo['share_img']}">
                                {php echo tpl_form_field_image('photo[share_img]', $photo['share_img']);}
                                <span class="help-block">图片建议大小：640×380像素</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group" style="text-align:center;">
            <div class="col-xs-12">
                <input name="submit" type="submit" value="　　保存　　" class="btn btn-primary"/>
                <input type="hidden" name="token" value="{$_W['token']}"/>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        window.optionchanged = false;
        //
        $(".js-atype input[name='photo[atype]']").click(function(){
            var obj = $(this);
            if (obj.val()!='2'){
                $("#options").addClass('markethide');
                $(".market").addClass('markethide');
            }else{
                $("#options").removeClass('markethide');
                $(".market").removeClass('markethide');
            }
        });
        //
        $(".js-kefu input[name='photo[kefu][type]']").click(function(){
            var obj = $(this);
            if (obj.val()!='2'){
                $(".kefu-url").hide();
                $(".kefu-qrcode").show();
            }else{
                $(".kefu-url").show();
                $(".kefu-qrcode").hide();
            }
        });
    });
    function check(form) {
        var id="{$photoid}",mid="{MERCHANTID}",proreview="{php echo $_W['_config']['proreview']==1 || ($_W['_config']['proreview']==2 && $photo['aprice']==0)?1:0;}";
        if (id!='' && proreview=='0' && mid!=''){
            if(!confirm('修改后将进入审核状态，是否确认？')) {
                return false;
            }
        }else{
            return true;
        }
    }
</script>
{elseif $op == 'display'}
<form class="form-horizontal" action="" method="post">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="panel-title">活动列表<span class="color-default pull-right">【点击活动标题复制连接】</span></div>
        </div>
        <div class="table-responsive">
            <table class="table table-hover table-bordered">
                <thead class="navbar-inner">
                <tr>
                    <th class="text-center" style="width:40px;">
                        <input type="checkbox" name="checkall" value="" id="checkall" onClick="var ck = this.checked; $(':checkbox').each(function(){this.checked = ck});">
                    </th>
                    <th class="text-center" style="width:40px;">ID</th>
                    <th class="text-left">活动标题</th>
                    <th class="text-left">轮播图</th>
                    <th class="text-left">背景图片</th>
                    <th class="text-left">分享标题</th>
                    <th class="text-left">分享描述</th>
                    <th class="text-left">分享链接</th>
                    <th class="text-left">分享图片</th>
                    <th class="text-center" style="width:330px;">操作</th>
                </tr>
                </thead>
                <tbody style="text-align: center;">
                {loop $photo $item}
                <tr>
                    <td class="text-center"><input type="checkbox" name="check" value="{$item['id']}" class="items"></td>
                    <td>{$item['id']}</td>
                    <td class="text-left">{$activity[$item['raceid']]['name']}</td>
                    <td class="text-left">
                        {loop unserialize($item['atlas']) $row}
                        <img src="{php echo tomedia($row)}" width="50px">
                        {/loop}
                    </td>
                    <td class="text-left">  <img src="{php echo tomedia($item['bgimg'])}" width="50px"></td>
                    <td class="text-left">{$item['share_title']}</td>
                    <td class="text-left">{$item['share_desc']}</td>
                    <td class="text-left">{$item['share_link']}</td>
                    <td class="text-left">
                        <img src="{php echo tomedia($item['share_img'])}" width="50px">
                    </td>
                    <td class="text-center">
                        <div class="btn-group">
                            <a href="{php echo web_url('photo/photo/post', array('photoid' => $item['id']))}" class="btn btn-success btn-sm">编辑</a>
                            <a href="javascript:void(0);" class="js-delete btn btn-danger btn-sm" data-id="{$item['id']}">删除</a>
                        </div>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </div>
    </div>
    <div class="pull-right">{$pager}</div>
</form>
<script>
    //删除效果b，单条操作
    $('.js-delete').click(function(e) {
        e.stopPropagation();
        var $this = $(this);
        var photoid = $this.data('id');
        util.nailConfirm(this, function(state) {
            if (!state) return;
            $.post("{php echo web_url('photo/photo/delete')}", {photoid : photoid}, function(data) {
                if(!data.errno){
                    $this.parents('tr').remove();
                }
                util.tips(data.message);
            }, 'json');
        }, {html:"确定删除？",placement: $this.data('placement')});
    });
</script>
{/if}
{aide_template 'common/footer'}
